﻿using System.Windows;
using BaMusaSoft.RPS.ViewModel;
using System.Threading;
using System.ComponentModel;


namespace BaMusaSoft.RPS.View
{
    /// <summary>
    /// Interaction logic for Shell.xaml
    /// </summary>
    public partial class Shell : Window
    {
        readonly MainViewModel _vm;
        Timer _timer;
        private const string PrinterJobsExist = "There is printing jobs, Do you want to cancel them?";
        public Shell()
        {
            InitializeComponent();
            _vm = MainViewModel.Current;
            DataContext = _vm;
        }

       

        private void WindowClosing(object sender, CancelEventArgs e)
        {
            _timer = new Timer(CheckIfServicesBusy, null, 0, 1000);
            CheckForExitSafty(e);

        }
        void CheckForExitSafty(CancelEventArgs e)
        {

            //if (!_vm.OkToClose)
            //{
            //    var reslt = MessageBox.Show(PrinterJobsExist, "RPS", MessageBoxButton.YesNo);
            //    if (reslt == MessageBoxResult.No)
            //    {
            //        e.Cancel = true;
            //        _timer.Dispose();
            //    }
            //    else
            //    {
            //        //_vm.StopServices();
            //        _timer.Dispose();
            //    }
            //}
            //else
            //{
            //    //_vm.StopServices();
            //    _timer.Dispose();
            //}
        }
        void CheckIfServicesBusy(object state)
        {
            //if (vm.OkToClose)
            //{
            //    vm.StopServices();
            //    vm.MessageNotification -= new EventHandler<NotificationEventArgs>(Helper.MessageNotificationEvent);
            //    Application.Current.Shutdown();
            //}
        }

        private void ExitClick(object sender, RoutedEventArgs e)
        {
            Close();
        }

        private void ShowClaimView(object sender, RoutedEventArgs e)
        {
            //Claim claim = new Claim();
            //ClaimsRepository repo = new ClaimsRepository();
            //ClaimViewModel vm = new ClaimViewModel(claim, repo);
            //ClaimViewWindow claimView = new ClaimViewWindow(vm);
            //claimView.Owner = this;
            //claimView.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner;
            //claimView.ShowDialog();
        }

        private void WindowLoaded(object sender, RoutedEventArgs e)
        {
            
        }

        
    }
}
